/*
 * @lc app=leetcode.cn id=345 lang=cpp
 *
 * [345] 反转字符串中的元音字母
 */

// @lc code=start
class Solution {
public:
    bool is_vowel(char c){
        if(c >= 'A' && c <= 'Z') c = c - 'A' + 'a';
        return c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u';
    }
    string reverseVowels(string s) {
        int i = 0, j = s.size() - 1;
        while(i < j){
            while(i < s.size() && !is_vowel(s[i])) i++;
            while(j >= 0 && !is_vowel(s[j])) j--;
            if(i < j) swap(s[i], s[j]);
            i++;
            j--;
        }
        return s;
    }
};
// @lc code=end

